package cn.edu.cqupt.cxcy.util;

import java.util.Map;
import java.util.Properties;

import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import cn.edu.cqupt.cxcy.model.Project;
import cn.edu.cqupt.cxcy.model.Team;

public class SendMail {
public boolean Congilre(Map<String,String> one)
{   boolean flag=false;
	Properties props = new Properties();
	props.put("mail.smtp.host", "smtp.qq.com");
	props.put("mail.smtp.auth", "true");
	try {
		PopupAuthenticator auth = new PopupAuthenticator();
		Session session = Session.getInstance(props, auth);
		session.setDebug(true);
		MimeMessage message = new MimeMessage(session);
		Address addressFrom = new InternetAddress(
				PopupAuthenticator.mailuser + "@qq.com", "团队");
		Address addressTo = new InternetAddress("410596154@qq.com", "LUO");
		message.setText(one.get("t_name")+"团队，"+one.get("inve_name")+"可能对你们的"+one.get("pro_name")+"项目感兴趣哦，赶快去联系该投资人吧，E-Mail:"+one.get("inve_email")+",Tel:"+one.get("inve_tel")+"。");
		message.setSubject("您有一封机密邮件哦");
		message.setFrom(addressFrom);
		message.addRecipient(Message.RecipientType.TO, addressTo);
		message.saveChanges();
		Transport transport = session.getTransport("smtp");
		transport.connect("smtp.qq.com", PopupAuthenticator.mailuser,
				PopupAuthenticator.password);
		transport.send(message);
		transport.close();
		System.out.println("sent suc");
		flag=true;
	} catch (Exception e) {
		System.out.println(e.toString());
		System.out.println("sent fail");
	}

return flag;}
}
class PopupAuthenticator extends Authenticator {
	public static final String mailuser = "965234557";
	public static final String password = "cqudpt364";

	public PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication(mailuser, password);
	}
}
